// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using Elastic.Transport;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.Security
{
	public sealed class SecurityPutUserRequestParameters : RequestParameters<SecurityPutUserRequestParameters>
	{
		[JsonIgnore]
		public Elastic.Clients.Elasticsearch.Refresh? Refresh { get => Q<Elastic.Clients.Elasticsearch.Refresh?>("refresh"); set => Q("refresh", value); }
	}

	public sealed partial class SecurityPutUserRequest : PlainRequestBase<SecurityPutUserRequestParameters>
	{
		public SecurityPutUserRequest(Elastic.Clients.Elasticsearch.Username username) : base(r => r.Required("username", username))
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.SecurityPutUser;
		protected override HttpMethod HttpMethod => HttpMethod.PUT;
		protected override bool SupportsBody => true;
		[JsonIgnore]
		public Elastic.Clients.Elasticsearch.Refresh? Refresh { get => Q<Elastic.Clients.Elasticsearch.Refresh?>("refresh"); set => Q("refresh", value); }

		[JsonInclude]
		[JsonPropertyName("email")]
		public string? Email { get; set; }

		[JsonInclude]
		[JsonPropertyName("full_name")]
		public string? FullName { get; set; }

		[JsonInclude]
		[JsonPropertyName("metadata")]
		public Dictionary<string, object>? Metadata { get; set; }

		[JsonInclude]
		[JsonPropertyName("password")]
		public string? Password { get; set; }

		[JsonInclude]
		[JsonPropertyName("password_hash")]
		public string? PasswordHash { get; set; }

		[JsonInclude]
		[JsonPropertyName("roles")]
		public IEnumerable<string>? Roles { get; set; }

		[JsonInclude]
		[JsonPropertyName("enabled")]
		public bool? Enabled { get; set; }
	}

	public sealed partial class SecurityPutUserRequestDescriptor : RequestDescriptorBase<SecurityPutUserRequestDescriptor, SecurityPutUserRequestParameters>
	{
		internal SecurityPutUserRequestDescriptor(Action<SecurityPutUserRequestDescriptor> configure) => configure.Invoke(this);
		public SecurityPutUserRequestDescriptor(Elastic.Clients.Elasticsearch.Username username) : base(r => r.Required("username", username))
		{
		}

		internal SecurityPutUserRequestDescriptor()
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.SecurityPutUser;
		protected override HttpMethod HttpMethod => HttpMethod.PUT;
		protected override bool SupportsBody => true;
		public SecurityPutUserRequestDescriptor Refresh(Elastic.Clients.Elasticsearch.Refresh? refresh) => Qs("refresh", refresh);
		public SecurityPutUserRequestDescriptor Username(Elastic.Clients.Elasticsearch.Username username)
		{
			RouteValues.Required("username", username);
			return Self;
		}

		private string? EmailValue { get; set; }

		private bool? EnabledValue { get; set; }

		private string? FullNameValue { get; set; }

		private Dictionary<string, object>? MetadataValue { get; set; }

		private string? PasswordValue { get; set; }

		private string? PasswordHashValue { get; set; }

		private IEnumerable<string>? RolesValue { get; set; }

		public SecurityPutUserRequestDescriptor Email(string? email)
		{
			EmailValue = email;
			return Self;
		}

		public SecurityPutUserRequestDescriptor Enabled(bool? enabled = true)
		{
			EnabledValue = enabled;
			return Self;
		}

		public SecurityPutUserRequestDescriptor FullName(string? fullName)
		{
			FullNameValue = fullName;
			return Self;
		}

		public SecurityPutUserRequestDescriptor Metadata(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector)
		{
			MetadataValue = selector?.Invoke(new FluentDictionary<string, object>());
			return Self;
		}

		public SecurityPutUserRequestDescriptor Password(string? password)
		{
			PasswordValue = password;
			return Self;
		}

		public SecurityPutUserRequestDescriptor PasswordHash(string? passwordHash)
		{
			PasswordHashValue = passwordHash;
			return Self;
		}

		public SecurityPutUserRequestDescriptor Roles(IEnumerable<string>? roles)
		{
			RolesValue = roles;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (!string.IsNullOrEmpty(EmailValue))
			{
				writer.WritePropertyName("email");
				writer.WriteStringValue(EmailValue);
			}

			if (EnabledValue.HasValue)
			{
				writer.WritePropertyName("enabled");
				writer.WriteBooleanValue(EnabledValue.Value);
			}

			if (!string.IsNullOrEmpty(FullNameValue))
			{
				writer.WritePropertyName("full_name");
				writer.WriteStringValue(FullNameValue);
			}

			if (MetadataValue is not null)
			{
				writer.WritePropertyName("metadata");
				JsonSerializer.Serialize(writer, MetadataValue, options);
			}

			if (PasswordValue is not null)
			{
				writer.WritePropertyName("password");
				JsonSerializer.Serialize(writer, PasswordValue, options);
			}

			if (!string.IsNullOrEmpty(PasswordHashValue))
			{
				writer.WritePropertyName("password_hash");
				writer.WriteStringValue(PasswordHashValue);
			}

			if (RolesValue is not null)
			{
				writer.WritePropertyName("roles");
				JsonSerializer.Serialize(writer, RolesValue, options);
			}

			writer.WriteEndObject();
		}
	}
}